home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / GridBagConstraints.java < prev    next >
Text File  |  1998-09-22  |  11KB  |  335 lines

  1. /*
  2.  * @(#)GridBagConstraints.java    1.11 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. /**
  17.  * The <code>GridBagConstraints</code> class specifies constraints 
  18.  * for components that are laid out using the 
  19.  * <code>GridBagLayout</code> class.
  20.  *
  21.  * @version 1.11, 07/01/98
  22.  * @author Doug Stein
  23.  * @see java.awt.GridBagLayout
  24.  * @since JDK1.0
  25.  */
  26. public class GridBagConstraints implements Cloneable, java.io.Serializable {
  27.  
  28.    /**
  29.      * Specify that this component is the next-to-last component in its 
  30.      * column or row (<code>gridwidth</code>, <code>gridheight</code>), 
  31.      * or that this component be placed next to the previously added 
  32.      * component (<code>gridx</code>, <code>gridy</code>). 
  33.      * @see      java.awt.GridBagConstraints#gridwidth
  34.      * @see      java.awt.GridBagConstraints#gridheight
  35.      * @see      java.awt.GridBagConstraints#gridx
  36.      * @see      java.awt.GridBagConstraints#gridy
  37.      * @since    JDK1.0
  38.      */
  39.   public static final int RELATIVE = -1;
  40.  
  41.    /**
  42.      * Specify that this component is the 
  43.      * last component in its column or row. 
  44.      * @since   JDK1.0
  45.      */
  46.   public static final int REMAINDER = 0;
  47.  
  48.    /**
  49.      * Do not resize the component. 
  50.      * @since   JDK1.0
  51.      */
  52.   public static final int NONE = 0;
  53.  
  54.    /**
  55.      * Resize the component both horizontally and vertically. 
  56.      * @since   JDK1.0
  57.      */
  58.   public static final int BOTH = 1;
  59.  
  60.    /**
  61.      * Resize the component horizontally but not vertically. 
  62.      * @since   JDK1.0
  63.      */
  64.   public static final int HORIZONTAL = 2;
  65.  
  66.    /**
  67.      * Resize the component vertically but not horizontally. 
  68.      * @since   JDK1.0
  69.      */
  70.   public static final int VERTICAL = 3;
  71.  
  72.    /**
  73.     * Put the component in the center of its display area.
  74.     * @since    JDK1.0
  75.     */
  76.   public static final int CENTER = 10;
  77.  
  78.    /**
  79.      * Put the component at the top of its display area,
  80.      * centered horizontally. 
  81.      * @since   JDK1.0
  82.      */
  83.   public static final int NORTH = 11;
  84.  
  85.     /**
  86.      * Put the component at the top-right corner of its display area. 
  87.      * @since   JDK1.0
  88.      */
  89.   public static final int NORTHEAST = 12;
  90.  
  91.     /**
  92.      * Put the component on the right side of its display area, 
  93.      * centered vertically.
  94.      * @since    JDK1.0
  95.      */
  96.   public static final int EAST = 13;
  97.  
  98.     /**
  99.      * Put the component at the bottom-right corner of its display area. 
  100.      * @since   JDK1.0
  101.      */
  102.   public static final int SOUTHEAST = 14;
  103.  
  104.     /**
  105.      * Put the component at the bottom of its display area, centered 
  106.      * horizontally. 
  107.      * @since   JDK1.0
  108.      */
  109.   public static final int SOUTH = 15;
  110.  
  111.    /**
  112.      * Put the component at the bottom-left corner of its display area. 
  113.      * @since   JDK1.0
  114.      */
  115.   public static final int SOUTHWEST = 16;
  116.  
  117.     /**
  118.      * Put the component on the left side of its display area, 
  119.      * centered vertically.
  120.      * @since    JDK1.0
  121.      */
  122.   public static final int WEST = 17;
  123.  
  124.    /**
  125.      * Put the component at the top-left corner of its display area. 
  126.      * @since   JDK1.0
  127.      */
  128.   public static final int NORTHWEST = 18;
  129.  
  130.    /**
  131.      * Specifies the cell at the left of the component's display area, 
  132.      * where the leftmost cell has <code>gridx = 0</code>. The value 
  133.      * <code>RELATIVE</code> specifies that the component be placed just 
  134.      * to the right of the component that was added to the container just 
  135.      * before this component was added. 
  136.      * <p>
  137.      * The default value is <code>RELATIVE</code>. 
  138.      * @see      java.awt.GridBagConstraints#gridy
  139.      * @since    JDK1.0
  140.      */
  141.   public int gridx;
  142.  
  143.    /**
  144.      * Specifies the cell at the top of the component's display area, 
  145.      * where the topmost cell has <code>gridy = 0</code>. The value 
  146.      * <code>RELATIVE</code> specifies that the component be placed just 
  147.      * below the component that was added to the container just before 
  148.      * this component was added. 
  149.      * <p>
  150.      * The default value is <code>RELATIVE</code>. 
  151.      * @see      java.awt.GridBagConstraints#gridx
  152.      * @since    JDK1.0
  153.      */
  154.   public int gridy;
  155.  
  156.    /**
  157.      * Specifies the number of cells in a row for the component's 
  158.      * display area. 
  159.      * <p>
  160.      * Use <code>REMAINDER</code> to specify that the component be the 
  161.      * last one in its row. Use <code>RELATIVE</code> to specify that the 
  162.      * component be the next-to-last one in its row. 
  163.      * <p>
  164.      * The default value is 1. 
  165.      * @see      java.awt.GridBagConstraints#gridheight
  166.      * @since    JDK1.0
  167.      */
  168.   public int gridwidth;
  169.  
  170.    /**
  171.      * Specifies the number of cells in a column for the component's 
  172.      * display area. 
  173.      * <p>
  174.      * Use <code>REMAINDER</code> to specify that the component be the 
  175.      * last one in its column. Use <code>RELATIVE</code> to specify that 
  176.      * the component be the next-to-last one in its column. 
  177.      * <p>
  178.      * The default value is 1.
  179.      * @see      java.awt.GridBagConstraints#gridwidth
  180.      * @since    JDK1.0
  181.      */
  182.   public int gridheight;
  183.  
  184.    /**
  185.      * Specifies how to distribute extra horizontal space. 
  186.      * <p>
  187.      * The grid bag layout manager calculates the weight of a column to 
  188.      * be the maximum <code>weighty</code> of all the components in a 
  189.      * row. If the resulting layout is smaller horizontally than the area 
  190.      * it needs to fill, the extra space is distributed to each column in 
  191.      * proportion to its weight. A column that has a weight zero receives no 
  192.      * extra space. 
  193.      * <p>
  194.      * If all the weights are zero, all the extra space appears between 
  195.      * the grids of the cell and the left and right edges. 
  196.      * <p>
  197.      * The default value of this field is <code>0</code>. 
  198.      * @see      java.awt.GridBagConstraints#weighty
  199.      * @since    JDK1.0
  200.      */
  201.   public double weightx;
  202.  
  203.    /**
  204.      * Specifies how to distribute extra vertical space. 
  205.      * <p>
  206.      * The grid bag layout manager calculates the weight of a row to be 
  207.      * the maximum <code>weightx</code> of all the components in a row. 
  208.      * If the resulting layout is smaller vertically than the area it 
  209.      * needs to fill, the extra space is distributed to each row in 
  210.      * proportion to its weight. A row that has a weight of zero receives no 
  211.      * extra space. 
  212.      * <p>
  213.      * If all the weights are zero, all the extra space appears between 
  214.      * the grids of the cell and the top and bottom edges. 
  215.      * <p>
  216.      * The default value of this field is <code>0</code>. 
  217.      * @see      java.awt.GridBagConstraints#weightx
  218.      * @since    JDK1.0
  219.      */
  220.   public double weighty;
  221.  
  222.    /**
  223.      * This field is used when the component is smaller than its display 
  224.      * area. It determines where, within the display area, to place the 
  225.      * component. Possible values are <code>CENTER<code>, 
  226.      * <code>NORTH<code>, <code>NORTHEAST<code>, <code>EAST<code>, 
  227.      * <code>SOUTHEAST<code>, <code>SOUTH<code>, <code>SOUTHWEST<code>, 
  228.      * <code>WEST<code>, and <code>NORTHWEST<code>.
  229.      * The default value is <code>CENTER</code>. 
  230.      * @since    JDK1.0
  231.      */
  232.   public int anchor;
  233.  
  234.    /**
  235.      * This field is used when the component's display area is larger 
  236.      * than the component's requested size. It determines whether to 
  237.      * resize the component, and if so, how. 
  238.      * <p>
  239.      * The following values are valid for <code>fill</code>: 
  240.      * <p>
  241.      * <ul>
  242.      * <li>
  243.      * <code>NONE</code>: Do not resize the component. 
  244.      * <li>
  245.      * <code>HORIZONTAL</code>: Make the component wide enough to fill 
  246.      *         its display area horizontally, but do not change its height. 
  247.      * <li>
  248.      * <code>VERTICAL</code>: Make the component tall enough to fill its 
  249.      *         display area vertically, but do not change its width. 
  250.      * <li>
  251.      * <code>BOTH</code>: Make the component fill its display area 
  252.      *         entirely. 
  253.      * </ul>
  254.      * <p>
  255.      * The default value is <code>NONE</code>. 
  256.      * @since   JDK1.0
  257.      */
  258.   public int fill;
  259.  
  260.    /**
  261.      * This field specifies the external padding of the component, the 
  262.      * minimum amount of space between the component and the edges of its 
  263.      * display area. 
  264.      * <p>
  265.      * The default value is <code>new Insets(0, 0, 0, 0)</code>. 
  266.      * @since    JDK1.0
  267.      */
  268.   public Insets insets;
  269.  
  270.    /**
  271.      * This field specifies the internal padding of the component, how much 
  272.      * space to add to the minimum width of the component. The width of 
  273.      * the component is at least its minimum width plus 
  274.      * <code>(ipadx * 2)</code> pixels. 
  275.      * <p>
  276.      * The default value is <code>0</code>. 
  277.      * @see      java.awt.GridBagConstraints#ipady
  278.      * @since    JDK1.0
  279.      */
  280.   public int ipadx;
  281.  
  282.    /**
  283.      * This field specifies the internal padding, that is, how much 
  284.      * space to add to the minimum height of the component. The height of 
  285.      * the component is at least its minimum height plus 
  286.      * <code>(ipady * 2)</code> pixels. 
  287.      * <p>
  288.      * The default value is 0. 
  289.      * @see      java.awt.GridBagConstraints#ipadx
  290.      * @since    JDK1.0
  291.      */
  292.   public int ipady;
  293.  
  294.   int tempX, tempY;
  295.   int tempWidth, tempHeight;
  296.   int minWidth, minHeight;
  297.  
  298.    /**
  299.      * Creates a <code>GridBagConstraint</code> object with 
  300.      * all of its fields set to their default value. 
  301.      * @since    JDK1.0
  302.      */
  303.   public GridBagConstraints () {
  304.     gridx = RELATIVE;
  305.     gridy = RELATIVE;
  306.     gridwidth = 1;
  307.     gridheight = 1;
  308.  
  309.     weightx = 0;
  310.     weighty = 0;
  311.     anchor = CENTER;
  312.     fill = NONE;
  313.  
  314.     insets = new Insets(0, 0, 0, 0);
  315.     ipadx = 0;
  316.     ipady = 0;
  317.   }
  318.  
  319.    /**
  320.     * Creates a copy of this grid bag constraint.
  321.     * @return     a copy of this grid bag constraint
  322.     * @since      JDK1.0
  323.     */
  324.   public Object clone () {
  325.       try { 
  326.       GridBagConstraints c = (GridBagConstraints)super.clone();
  327.       c.insets = (Insets)insets.clone();
  328.       return c;
  329.       } catch (CloneNotSupportedException e) { 
  330.       // this shouldn't happen, since we are Cloneable
  331.       throw new InternalError();
  332.       }
  333.   }
  334. }
  335.